package com.imau.controller;

import com.alibaba.fastjson.JSON;
import com.imau.bean.Brand;
import com.imau.service.BrandService;
import com.imau.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "BrandGetServlet", value = "/BrandGetServlet")
public class BrandGetServlet extends HttpServlet {
    private BrandService service = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");
        response.setContentType("text/json;charset=utf-8");

        Brand brand = service.getById(Integer.valueOf(id));

        response.getWriter().write(JSON.toJSONString(brand));


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request,response);
    }
}
